package com.woniuxy.ams.service.impl;

import com.woniuxy.ams.dao.DetailDao;
import com.woniuxy.ams.entity.Detail;
import com.woniuxy.ams.entity.User;
import com.woniuxy.ams.service.DetailService;
import com.woniuxy.ams.utils.String2Int;
import com.woniuxy.ams.utils.SystemUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class DetailServiceImpl implements DetailService {
    DetailDao detailDao;
    @Autowired(required = false)
    public void setDetailDao(DetailDao detailDao) {
        this.detailDao = detailDao;
    }

    @Override
    public int insert(Detail detail) {
        return detailDao.insert(detail);
    }

    @Override
    public int delete(int id) {
        return detailDao.delete(id);
    }

    @Override
    public List<Detail> findAll() {
        return detailDao.findAll();
    }

    @Override
    public int update(Detail detail) {
        return detailDao.update(detail);
    }

    @Override
    public List<Detail> findByIdStr(String idStr) {
        int[] pidArr = String2Int.getIntArr(idStr);
        User loginUser = SystemUtils.getLoginUser();
        String name = loginUser.getName();
        List<Detail> byIdStr = detailDao.findByIdStr(pidArr);
        for (Detail detail : byIdStr) {
            detail.setUpdatedName(name);
        }
        return byIdStr;
    }
}
